home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / remotedesktop / citrix / icadecrypt.c < prev   
C/C++ Source or Header  |  2005-02-12  |  2KB  |  105 lines

  1. /*
  2.   icadecrypt.c
  3.  
  4.   Decrypt stored Citrix ICA passwords (in appsrv.ini).
  5.  
  6.   Dug Song <dugsong@monkey.org>
  7. */
  8.  
  9. #include <sys/types.h>
  10. #include <netinet/in.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. int
  16. hex_decode(char *src, u_char *dst, int outsize)
  17. {
  18.   char *p, *pe;
  19.   u_char *q, *qe, ch, cl;
  20.   
  21.   pe = src + strlen(src);
  22.   qe = dst + outsize;
  23.  
  24.   for (p = src, q = dst; p < pe && q < qe && isxdigit((int)*p); p += 2) {
  25.     ch = tolower(p[0]);
  26.     cl = tolower(p[1]);
  27.     
  28.     if ((ch >= '0') && (ch <= '9')) ch -= '0';
  29.     else if ((ch >= 'a') && (ch <= 'f')) ch -= 'a' - 10;
  30.     else return (-1);
  31.     
  32.     if ((cl >= '0') && (cl <= '9')) cl -= '0';
  33.     else if ((cl >= 'a') && (cl <= 'f')) cl -= 'a' - 10;
  34.     else return (-1);
  35.     
  36.     *q++ = (ch << 4) | cl;
  37.   }
  38.   return (q - dst);
  39. }
  40.  
  41. int
  42. ica_decrypt(u_char *pass, int len)
  43. {
  44.   u_short i;
  45.   u_char *p, key;
  46.  
  47.   if (len < 4)
  48.     return (0);
  49.  
  50.   i = ntohs(*(u_short *)pass);
  51.   
  52.   if (i != len - 2)
  53.     return (0);
  54.   
  55.   key = pass[2];
  56.   p = pass + 3;
  57.   
  58.   for (i -= 2; i > 0; i--)
  59.     p[i] = p[i - 1] ^ p[i] ^ key;
  60.  
  61.   p[0] ^= (key | 'C');
  62.   
  63.   i = len - 3;
  64.   memmove(pass, pass + 3, i);
  65.   pass[i] = '\0';
  66.   
  67.   return (1);
  68. }
  69.  
  70. void
  71. usage(void)
  72. {
  73.   fprintf(stderr, "Usage: icadecrypt <file>\n");
  74.   exit(1);
  75. }
  76.  
  77. int
  78. main(int argc, char *argv[])
  79. {
  80.   FILE *f;
  81.   u_char line[1024], pass[128];
  82.   int len;
  83.  
  84.   if (argc != 2 || *argv[1] == '-')
  85.     usage();
  86.  
  87.   if ((f = fopen(argv[1], "r")) == NULL) {
  88.     perror("fopen");
  89.     exit(1);
  90.   }
  91.   while (fgets(line, sizeof(line), f) != NULL) {
  92.     if (strncmp(line, "Password=", 9) == 0) {
  93.       len = hex_decode(line + 9, pass, sizeof(pass));
  94.       if (ica_decrypt(pass, len))
  95.         printf("; icadecrypt: [%s]\n", pass);
  96.     }
  97.     printf("%s", line);
  98.   }
  99.   fclose(f);
  100.  
  101.   exit(0);
  102. }
  103.  
  104. /* 5000. */
  105.